package eerbaar.v2.pattern.client.internal;

import java.util.ArrayList;
import java.util.List;

public class ProgramNameGenerator {

    class Data {
        final String program;
        final String[] list;

        Data(String program, String[] list) {
            this.program = program;
            this.list = list;
        }

        String getPrefered() {
            return this.list[0];
        }
    }

    private final List<Data> list = new ArrayList<Data>();

    public ProgramNameGenerator() {
        populateEatABone();
        populateRunFromABug();
        populateHideInAHouse();
        populateMakeAFriend();
    }

    public String getPrefered(String program) {

        Data found = null;
        for (Data data : this.list) {
            if (program.contains(data.program)) {
                found = data;
                break;
            }
        }

        if (found == null) {
            return null;
        }

        return found.getPrefered();
    }

    private void populateEatABone() {
        String[] names = new String[] { "eat-a-bone", "goto-a-bone" };
        Data data = new Data("bone +", names);
        this.list.add(data);
    }

    private void populateHideInAHouse() {
        String[] names = new String[] { "hide-in-a-house", "house" };
        Data data = new Data("house +", names);
        this.list.add(data);
    }

    private void populateMakeAFriend() {
        String[] names = new String[] { "run-in-pack" };
        Data data = new Data("dog +", names);
        this.list.add(data);
    }

    private void populateRunFromABug() {
        String[] names = new String[] { "run-from-bug", "hide" };
        Data data = new Data("bug -", names);
        this.list.add(data);
    }

}
